﻿using Microsoft.AspNetCore.Mvc;
using PMS.Services.Authentication.Externel;
using System.Collections.Generic;

namespace PMS.Web.Framework.Controllers
{
    public class BasePluginController : BaseController
    {
        /// <summary>
        /// Add errors that occurred during authentication
        /// </summary>
        /// <param name="errors">Collection of errors</param>
        /// <param name="returnUrl">URL to which the user will return after authentication</param>
        /// <returns>Result of an authentication</returns>
        protected virtual IActionResult ErrorAuthentication(IEnumerable<string> errors, string returnurl = null)
        {
            foreach (var error in errors)
                ExternalAuthorizerHelper.AddErrorsToDisplay(error);

            return new RedirectToActionResult("ErrorPage", "Common", !string.IsNullOrEmpty(returnurl) ? new { returnurl } : null);
        }
    }
}
